﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Permissions;
using System.Runtime.Serialization;

namespace MetaCollection.ContentService.Http
{
	/// <summary>
	/// Server Http Exception
	/// </summary>
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors"), Serializable]
	public class ServerException : HttpException, ISerializable
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ServerException"/> class.
		/// </summary>
		public ServerException() : base() { Code = ServerErrorStatus.None; }
		/// <summary>
		/// Initializes a new instance of the <see cref="ServerException"/> class.
		/// </summary>
		/// <param name="code">The code.</param>
		public ServerException(ServerErrorStatus code)
			: base((int)code, Enum.GetName(typeof(ServerErrorStatus), code))
		{ Code = code; }

		/// <summary>
		/// Initializes a new instance of the <see cref="HttpException&lt;T&gt;"/> class.
		/// </summary>
		/// <param name="httpCode">The HTTP code.</param>
		/// <param name="message">The message.</param>
		public ServerException(ServerErrorStatus code, string message)
			: base((int)code, message)
		{ Code = code; }
		/// <summary>
		/// Initializes a new instance of the <see cref="HttpException&lt;T&gt;"/> class.
		/// </summary>
		/// <param name="httpCode">The HTTP code.</param>
		/// <param name="message">The message.</param>
		/// <param name="innerException">The inner exception.</param>
		public ServerException(ServerErrorStatus code, string message, Exception innerException)
			: base((int)code, message, innerException)
		{ Code = code; }
		/// <summary>
		/// The HTTP Status Code
		/// </summary>
		public ServerErrorStatus Code { get; private set; }
		/// <summary>
		/// Gets information about the exception and adds it to the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> object.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that holds the contextual information about the source or destination.</param>
		[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
		public new virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}
	}
}
